package chapter2;

import java.util.Random;

/**
 * @author ycj
 * @version 1.0
 * @description: TODO
 * @date 2022/5/17
 */
public class Source2_8 {
    static int data=0;
    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(new Random().nextInt(50));
                    System.out.println("data=" + data);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        //父线程 对子线程启动前 对共享变量的更新 对于子线程是可见的
        data=1;
        thread.start();
        Thread.sleep(new Random().nextInt(50));
        data=2;

    }
}
